import { SDK } from "../Framework/SDK/ISDK";
import Mainloop from "./Mainloop";
import { ProcGame } from "./ProcGame";

export class ProcInit  {

    async onEnter(): Promise<any> {
        try{
            await SDK.instance.Login();
        }
        catch
        {
            return new Promise<any>((resolve, reject) =>{
                resolve(false);
            })
        }
        
        
        let userInfo = await SDK.instance.GetUserInfo();
                
        let headImgNode = cc.find("Canvas/cocos");
        let spriteComponent = headImgNode.getComponent(cc.Sprite);
        SDK.instance.GetUserImage(userInfo.avatarUrl, spriteComponent);

        let nameNode = cc.find("Canvas/label");
        let labelComponent = nameNode.getComponent(cc.Label);
        labelComponent.string = userInfo.nickName;
        
        return new Promise<any>((resolve, reject) =>{
            resolve(true);
        })
    }

    onProcess(dt) {
        Mainloop.instance.changeProc(new ProcGame());
    }

    onLeave() {

    }
}
